<template>
  <div class="view-particle">
    <fx-card title="基础用法">
      <fx-particle class="particle"></fx-particle>
      <template #hide>
        <pre v-highlight="base"><code></code></pre>
      </template>
    </fx-card>
    <fx-card title="点击动态添加粒子点 (超出最大值时,自动删除多余粒子点)">
      <fx-particle class="particle" :dots="10" is-add :radius="10" random-radius/>
      <template #hide>
        <pre v-highlight="add"><code></code></pre>
      </template>
    </fx-card>
    <fx-card title="暂停">
      <fx-particle class="particle" :stop="stopType" :speedX="speedX" :speedY="speedY"/>
      <div style="display:flex;align-items: center" class="mt10">
        <fx-switch v-model="stopType" close-text="开始" open-text="暂停"></fx-switch>
        <span class="ml10">横向速度:</span>
        <fx-input-number :min="0" :max="100" :step="0.5" v-model="speedX" size="mini"></fx-input-number>
        <span class="ml10">纵向速度:</span>
        <fx-input-number :min="0" :max="100" :step="0.5" v-model="speedY" size="mini"></fx-input-number>
      </div>
      <template #hide>
        <pre v-highlight="stop"><code></code></pre>
      </template>
    </fx-card>
    <fx-card title="自定义颜色/连线长度">
      <fx-particle class="particle" :color="dotsColorIsRandom?'random':dotsColor"
                   :line-color="lineColorIsRandom?'random':lineColor" :connect="connect"/>
      <fx-row>
        <fx-col :span="6">
          粒子点颜色：
          <fx-radio v-model="dotsColorIsRandom" :label="false">
            <input type="color" v-model="dotsColor" class="mr20">
          </fx-radio>
          <fx-radio v-model="dotsColorIsRandom" :label="true">
            随机色
          </fx-radio>
        </fx-col>
        <fx-col :span="6">
          连接线颜色：
          <fx-radio v-model="lineColorIsRandom" :label="false">
            <input type="color" v-model="lineColor" class="mr20">
          </fx-radio>
          <fx-radio v-model="lineColorIsRandom" :label="true">
            随机色
          </fx-radio>
        </fx-col>
        <fx-col :span="6">
          连线距离：
          <fx-input-number v-model="connect" size="mini"></fx-input-number>
        </fx-col>
      </fx-row>
      <template #hide>
        <pre v-highlight="color"><code></code></pre>
      </template>
    </fx-card>
    <fx-card title="鼠标移入">
      <fx-particle class="particle" :mouse-line="mouseLine" :mouse-line-color="mouseLineColor"/>
      <div style="display:flex;align-items: center" class="mt10">
        <fx-input-number v-model="mouseLine" size="mini"></fx-input-number>
        连接线颜色：<input type="color" v-model="mouseLineColor">
      </div>
      <template #hide>
        <pre v-highlight="mouse"><code></code></pre>
      </template>
    </fx-card>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
  name: 'viewParticle',
  setup () {
    const stopType = ref<boolean>(false)
    const speedX = ref<number>(3)
    const speedY = ref<number>(3)
    const dotsColor = ref<string>('#ff6600')
    const lineColor = ref<string>('#ff6699')
    const dotsColorIsRandom = ref<boolean>(false)
    const lineColorIsRandom = ref<boolean>(false)
    const connect = ref<number>(60)
    const mouseLine = ref<number>(60)
    const mouseLineColor = ref<string>('#ff00ff')
    const base = '<fx-particle style="width: 100%;height: 200px;"></fx-particle>'
    const add = '<fx-particle style="width: 100%;height: 200px;" :dots="10" is-add :radius="10" random-radius></fx-particle>'
    const stop = `<fx-particle style="width: 100%;height: 200px;" :stop="stopType" :speedX="speedX" :speedY="speedY"/>
<div style="display:flex;align-items: center">
  <fx-switch v-model="stopType" close-text="开始" open-text="暂停"></fx-switch>
  <span class="ml10">横向速度:</span>
  <fx-input-number :min="0" :max="100" :step="0.5" v-model="speedX"></fx-input-number>
  <span class="ml10">纵向速度:</span>
  <fx-input-number :min="0" :max="10" :step="0.5" v-model="speedY"></fx-input-number>
</div>`
    const color = `<fx-particle class="particle" :color="dotsColorIsRandom?'random':dotsColor" :line-color="lineColorIsRandom?'random':lineColor" :connect="connect"/>
<fx-row>
  <fx-col :span="6">
    粒子点颜色：
    <fx-radio v-model="dotsColorIsRandom" :label="false">
      <input type="color" v-model="dotsColor" class="mr20">
    </fx-radio>
    <fx-radio v-model="dotsColorIsRandom" :label="true">
      随机色
    </fx-radio>
  </fx-col>
  <fx-col :span="6">
    连接线颜色：
    <fx-radio v-model="lineColorIsRandom" :label="false">
      <input type="color" v-model="lineColor" class="mr20">
    </fx-radio>
    <fx-radio v-model="lineColorIsRandom" :label="true">
      随机色
    </fx-radio>
  </fx-col>
  <fx-col :span="6">
    连线距离：
    <fx-input-number v-model="connect" size="mini"></fx-input-number>
  </fx-col>
</fx-row>`
    const mouse = `<fx-particle style="width: 100%;height: 200px;" :mouse-line="mouseLine" :mouse-line-color="mouseLineColor"></fx-particle>
<fx-input-number v-model="mouseLine"></fx-input-number>
连接线颜色：<input type="color" v-model="mouseLineColor">`

    return {
      stopType,
      speedX,
      speedY,
      dotsColor,
      lineColor,
      dotsColorIsRandom,
      lineColorIsRandom,
      connect,
      mouseLine,
      mouseLineColor,
      base,
      add,
      stop,
      color,
      mouse
    }
  }
})
</script>

<style scoped lang="scss">
.view-particle {
  .particle {
    width: 100%;
    height: 200px;
    border: 1px solid #ccc
  }
}
</style>
